﻿using System.ServiceModel;
using System.ServiceModel.Activation;
using Ops.Mpc.ExampleApplication.Web.BusinessObjects;
using System.Threading;
using Ops.Mpc.ExampleApplication.Web.BusinessObjects.Filters;
using System;
using System.Web;
using System.Diagnostics;

namespace Ops.Mpc.ExampleApplication.Web.Services
{
    [ServiceContract(SessionMode=SessionMode.Allowed)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class ExampleService
    {
        #region Fields & Properties
        public BusinessObjectManager BusinessObjectManager
        {
            get
            {
                return new BusinessObjectManager();
            }
        }

        #endregion

        #region Methods
        [OperationContract]
        public Person CreatePerson(string firstName, string lastName)
        {
            Wait();
            return  BusinessObjectManager.CreatePerson(firstName, lastName);
        }

        [OperationContract(Name="GetPersonsPager")]
        public Pager GetPersons(Filter[] filters)
        {
            Wait();
            return  BusinessObjectManager.GetPersons(filters);
        }

        [OperationContract]
        public Person[] GetPersons(Pager pager)
        {
            Wait();            
            Debug.WriteLine(HttpContext.Current.Session.SessionID);
            return  BusinessObjectManager.GetPersons(pager);

        }

        private void Wait()
        {
            // Make it feel more like a real database transaction
            Thread.Sleep(500);
        }

        #endregion
    }
}
